  function afterAjaxLoadProducts(data, update) {
    if (data.status && data.status == 200) {
      var html = '';
      var product;
      for (key in data.products) {
        product = data.products[key];
        html += '<li class="list_product_item"><div class="box_list list_product_item_inner"> <a class="list_product_link box_list_main" rel="nofollow" title="' + product.name + '" href="' + product.url + '" data-role="none" data-ajax="false"><div class="list_product_frame"><div class="list_product_img_block"> <img class="list_product_img _lazyLoadImage" src="' + product.thumb_url + '" alt="' + product.name + '" border="0"/></div><div class="list_product_text_block mb5"><p class="list_product_brand rdstr">' + product.name + '</p><p class="list_product_brand rdstr">' + product.price + '</p>';

        if (product.list_price) {
          html += '<p class="list_product_brand rdstr">' + product.list_price + '</p>';
        }
        if (product.discount) {
          html += '<p class="list_product_brand rdstr">' + product.discount + 'OFF</p>';
        }

        html += '</div><span class="arrow"></span>';
        html += '</div></a></div></li>';
      }
      $("#" + update).append(html);
    }
  }
  function gotoseach(){
    var search_keyword = $('#search_keyword').val();
    if(search_keyword !=""){
      window.location.href= "/search/"+search_keyword+"?rel=msearch";
     }else{
      $("#search_keyword").focus();
     }
  }
  function hide_addp_cart_success(){
    document.getElementById('addp_cart_success').style.display='none'
  }

  function afterChangeCountry(el, data, state_id) {
    if (data.status == 200) {
      if (state_id) {
        var state_el = $("#" + state_id);
      } else {
        var state_el = $("#state_id");
      }
      state_el.find('option').remove();
      for (var key in data.states) {
        state_el.append('<option value="' + key + '">' + data.states[key] + '</option>');
      }
    } else {
      alert(data.info);
    }
  }

  function setLocation(url) {
    window.location.href = url;
  }

  function afterDeleteWish(el, data) {
    if (data.status == 200) {
      alert(data.message);
      // swal('Successful!', data.message, 'success');
      //        $(el).parents('tr').fadeout('slow').remove();
      $(el).parent().parent().remove();
    } else {
      alert(data.message);
      // swal('Oops!', data.message, 'error');
    }
  }

  function afterSubscription(el, data) {
    if (data.status == 200) {
      alert('購読を成功に予約しました。');
      $("#newsletter-email").val('');
    } else {
      alert('サーバエラーが発生しました。');
      $("#newsletter-email").val('');
    }
  }

  $(function() {

    $("#checkoutForm").on('submit', function () {
      $("#loading").show();
      $('section.cashierEditSumit').html('<em><strong>loading...</strong></em>');
    });

    $(".onceClick").on('click', function () {
      $(this).attr('disabled', true).find('span').html('<em class="fwb"><strong>loading...</strong></em>').parents('form').submit();
    });

    $(".on-selected-change-url").on('change', function() {
      var url = $(this).val();
      if (url) {
        window.location.href = url;
      }
    });

    $("#gotoreview").click(function() {
      $("#gotoreviewspan").click();
      //              location.hash="gotoreviewspan";
      $("html,body").animate({
        scrollTop: $("#gotoreviewspan").offset().top - 130
      }, 500)
    });

//pull down load more product
    // if ($("#ajaxLoadFormoreproducts").length > 0) {
    //   var loadingData = false;
    //   $(window).scroll(function() {
    //     var winHei = $(window).height();
    //     var winST = $(window).scrollTop();
    //     var load_click = $(".load_click:visible");
    //     var eleTop = load_click.offset().top;
    //     var datajson = {};
    //     if (eleTop >= winST && eleTop < (winST + winHei) && loadingData == false) {
    //       $("#ajaxLoadFormoreproducts :input").each(
    //         function() {
    //           var key = $(this).attr('name');
    //           var value = $(this).val();
    //           datajson[key] = value;
    //         }
    //       );
    //       // console.log('json:'+JSON.stringify(datajson));
    //       // var  datajson = {category: thiscategory,sort:'asc',page:thispage};
    //       $.request('onLoadMoreProducts', {
    //         data: datajson,
    //         update: {
    //           'catagory/loadmoreproducts': "@#productsContent1"
    //         },
    //         complete: function(data) { /* do something */
    //         var response=JSON.parse(data.responseText)["catagory/loadmoreproducts"];
    //         console.log(response);
    //         if(response==''){
    //           $("#wait_for_load_list_preorder").html('已经加载全部数据');
    //         }

    //         }
    //       })
    //       var thispage = $("#ajaxLoadFormoreproducts_page").val();
    //       var nextpage = parseInt(thispage) + 1;
    //       $("#ajaxLoadFormoreproducts_page").val(nextpage);

    //       loadingData = true;
    //       setTimeout(function() {
    //         loadingData = false;
    //       }, 1000);
    //     }
    //   });
    // }

    //click button load more products
    $("#ajaxLoadFormoreproductsbutton").click(function(){
        $("#wait_for_load_list_preorder_text").hide();
        $("#wait_for_load_list_preorder_img").show();
         var datajson = {};
        $("#ajaxLoadFormoreproducts :input").each(
          function() {
            var key = $(this).attr('name');
            datajson[key] = $(this).val();
          }
        );
        // console.log('json:'+JSON.stringify(datajson));
        // var  datajson = {category: thiscategory,sort:'asc',page:thispage};
        $.request('onLoadMoreCategoryProducts', {
          data: datajson,
          update: {
            'catagory/loadmoreproducts': "@#productsContent1"
          },
          complete: function(data) { /* do something */
          var response=JSON.parse(data.responseText)["catagory/loadmoreproducts"];
          console.log(response);
          $("#wait_for_load_list_preorder_img").hide();
          if(response==''){
            $("#wait_for_load_list_preorder_text").show();
          }else{
            //do sth
          }
          }
        })
        var thispage = $("#ajaxLoadFormoreproducts_page").val();
        var nextpage = parseInt(thispage) + 1;
        $("#ajaxLoadFormoreproducts_page").val(nextpage);

        loadingData = true;
        setTimeout(function() {
          loadingData = false;
        }, 1000);

    });
    //控制图片大小

    // window.onload = function(){
    //   var sq_productH =$(".list_product_img_block img.productImgH").eq(0).height();
    //   $(".list_product_img_block img.productImgH").height(sq_productH);
    // }
  });
